import openpyxl
import datetime
import time
import os
import sys
import logging
import ChengBanBuMen
import ReplaceBuMen
import GenerateCharts
from hanchlogger import logger
import hanchxl
import docx
from docx.shared import RGBColor
import infoChengBanGongDan
import loadExcelFileByColumn
from openpyxl.utils import get_column_letter
import Configuration
import JieDanInFoFromQuanBu


timeCur = datetime.datetime.now()
timeCurStr = '{}-{}-{} {}:{}:{}'.format(timeCur.year, timeCur.month, timeCur.day, timeCur.hour, timeCur.minute, timeCur.second)
# dirPath = os.path.dirname(os.path.realpath(sys.executable))
# dirPath ='\\\\172.16.10.175\\共享文件\\数据组\\2023年文件\\杨书记调度会\\生成每日必办'
dirPath ='E:\\日常工作\\数据组日常工作-春节\\生成每日必办'

logFile = dirPath + '\\MustDoEveryDay.log'
logger.get_log(logFile, 'LoggerMustDoEveryDay', logging.DEBUG)

timeYesterdayStr = datetime.datetime.fromtimestamp(timeCur.timestamp()-60*60*24).strftime('%Y-%m-%d')
timeYesterdayStr = timeYesterdayStr + '  {}:{}:{}'.format(timeCur.hour, timeCur.minute, timeCur.second)
datatimeYesterday = datetime.datetime.strptime(timeYesterdayStr, '%Y-%m-%d %H:%M:%S')
timeYesterday = time.strptime(timeYesterdayStr, '%Y-%m-%d %H:%M:%S')
timeYesterdayStamp = int(time.mktime(timeYesterday))
logger.debug('昨天（日期）：{}    昨天（时间戳）：{}'.format(timeYesterdayStr, timeYesterdayStamp))

timeTomorrowStr = datetime.datetime.fromtimestamp(timeCur.timestamp()+60*60*24).strftime('%Y-%m-%d')
timeTomorrowStr = timeTomorrowStr + '  {}:{}:{}'.format(timeCur.hour, timeCur.minute, timeCur.second)
datatimeTomorrow = datetime.datetime.strptime(timeTomorrowStr, '%Y-%m-%d %H:%M:%S')
timeTomorrow = time.strptime(timeTomorrowStr, '%Y-%m-%d %H:%M:%S')
timeTomorrowStamp = int(time.mktime(timeTomorrow))
strTomorrow = '{}年{}月{}日'.format(datatimeTomorrow.year, datatimeTomorrow.month, datatimeTomorrow.day)
logger.debug('明天（日期）：{}    明天（时间戳）：{}'.format(timeTomorrowStr, timeTomorrowStamp))

strToday = '{}月{}日'.format(timeCur.month, timeCur.day)


fileJieDanJieDao = dirPath + '\\每日必办-工单总数-已匹配承办部门.xlsx'
fileJieDanJianWei = dirPath + '\\每日必办-工单总数-建委-已匹配承办部门.xlsx'
fileKaoHeJianWeiCountHeBingSave = dirPath + '\\每日必办-工单总数-已匹配承办部门-合并.xlsx'

bookJieDanJieDao = openpyxl.load_workbook(fileJieDanJieDao, data_only=True)
sheetJieDanJieDao = bookJieDanJieDao.active
maxRowJieDanJieDao = sheetJieDanJieDao.max_row
maxColJieDanJieDao = sheetJieDanJieDao.max_column
logger.debug('每日必办-工单总数-已匹配承办部门.xlsx -------行数：{}行    列数：{}列'.format(maxRowJieDanJieDao, maxColJieDanJieDao))

bookJieDanJianWei = openpyxl.load_workbook(fileJieDanJianWei, data_only=True)
sheetJieDanJianWei = bookJieDanJianWei.active
maxRowJieDanJianWei = sheetJieDanJianWei.max_row
maxColJieDanJianWei = sheetJieDanJianWei.max_column
logger.debug('每日必办-工单总数-建委-已匹配承办部门.xlsx -------行数：{}行    列数：{}列'.format(maxRowJieDanJianWei, maxColJieDanJianWei))

for indexJieDao in range(1, maxColJieDanJieDao + 1):
    valueColJieDao = '{}'.format(sheetJieDanJieDao.cell(1, indexJieDao).value).strip()
    indexColJianWei = hanchxl.get_col_index(sheetJieDanJianWei, valueColJieDao)
    if indexColJianWei is not None:
        for indexJianWei in range(2, maxRowJieDanJianWei + 1):
            rowJieDao = maxRowJieDanJieDao + indexJianWei - 1
            sheetJieDanJieDao.cell(rowJieDao, indexJieDao).value = sheetJieDanJianWei.cell(indexJianWei, indexColJianWei).value


bookJieDanJieDao.save(fileKaoHeJianWeiCountHeBingSave)




